<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
//财务明细
class FinanceRecord extends Model
{
    use HasFactory;

    protected $table = 'sp_finance_record';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //is_delete是否删除  1是 2否
    const IS_DELETE = 1;//是
    const NOT_DELETE = 0;//否

    const FLOW_TYPE = [
        '1'=>'平台->商家',
    ];

    const SUBJECT = [
        '1'=>'租金',
    ];

    const TYPE_SHOP_SETTLE = 1;//商户结算
    const SUBJECT_LEASE = 1;//商户租金结算
    const FLOW_TYPE_PLAT_TO_SHOP = 1;//商户租金结算


    const TYPE = [
        '1'=>'商户结算',
    ];

    protected function user(){
        return $this->belongsTo(MemberOther::class,'uid','id')->select(['cert_no', 'cert_name']);
    }


    public function GetOne($cate_id)
    {
        $category = $this->where([['id', $cate_id]])
            ->with('user')
            ->where('is_delete',0)
            ->select('id', 'name', 'image')
            ->first();
        $category = $category ? $category->toArray() : [];
        return $category;
    }

    /**
     * 获取列表记录
     */
    public function getList($where=[])
    {
        $category = $this->where($where)
            ->with('user')
            ->where('is_delete',0)
            ->get();
        $category = $category ? $category->toArray() : [];
        return $category;
    }



    //添加
    public function addData($data)
    {
        return $this->insert($data);
    }

    //根据id修改
    public function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $this->where($where)->update($data);
    }

}
